<?php


namespace App\Services\Game;


use App\DTOS\Admin\MemberDTO;
use App\Models\Game\Member;
use App\Utils\MyLog;

class MemberService
{
    /**
     * @param MemberDTO $DTO
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function paginate(MemberDTO $DTO){

        $model = Member::query();
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $id = $DTO->getId();
        $username = $DTO->getUsername();
        $mobile = $DTO->getMobile();

        $customerId = $DTO->getCustomerId();
        $createTimeBegin = $DTO->getCreateTimeBegin();
        $createTimeEnd = $DTO->getCreateTimeEnd();

        if ($id){
            $model->where('id',$id);
        }
        if ($customerId){
            $model->where('openid',$customerId);
        }

        if ($mobile){
            $model->where('mobile',$mobile);
        }
        if ($username){
            $model->where('username','like',"%$username%");
        }
        if ($createTimeBegin) {
            $model->where('createtime','>=',strtotime($createTimeBegin));
        }
        if ($createTimeEnd){
            $model->where('createtime','<=',strtotime($createTimeEnd));
        }
        return $model->orderByDesc('id')->paginate($perPage,'*','page',$page);
    }
}
